/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.q7solucoes.lazerbrwebservicejclient.tests;

import br.com.q7solucoes.commons.wordpress.WPPost;
import br.com.q7solucoes.commons.wordpress.WPPostDAO;
import br.com.q7solucoes.lazerbrwebservicejclient.LazerBRWebServiceJClient;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

/**
 *
 * @author elenilson
 */
public class TestImpl {
    
    public static void main(String[] args) throws SQLException {
        testAddPost();
    }

    private static void testAddPost() {
        List<String>  tags = new ArrayList<String>();
        List<String>  categories = new ArrayList<String>();

        categories.add("cinema");
        String title = "teste de elenilson 19";

        LazerBRWebServiceJClient LazerBRWebServiceJClient = new LazerBRWebServiceJClient();
        GregorianCalendar date = new GregorianCalendar();
        date.setTime(GregorianCalendar.getInstance().getTime());
        
        boolean result = LazerBRWebServiceJClient.addPost(title+ "çuúã", "conteudo éçpoeúi", title, 
                "http://www.lazerjp.com.br/wp-content/uploads/2011/04/cineespaco.jpg", 
                date, categories, tags);
        
        System.out.println(">> " + result);
    }
    
    private static WPPostDAO getWPPostDAO() {
        String mysqlDatabaseHost = "pegadinhadomalandro";
        String mysqlDatabase = "pegadinhadomalandro";
        String mysqlDatabaseCode = "pegadinhadomalandro";
        String mysqlDatabaseUser = "pegadinhadomalandro";
        String mysqlDatabasePassword = "pegadinhadomalandro";
        
        try{
            return new WPPostDAO(mysqlDatabase, mysqlDatabaseHost, mysqlDatabaseUser, mysqlDatabasePassword, mysqlDatabaseCode);
        }catch(Exception ex){
            return null;
        }
    }

    private static void testGetPosts() throws SQLException {
        GregorianCalendar beginCalendar = new GregorianCalendar(2012, 1, 4);
        GregorianCalendar endCalendar = new GregorianCalendar(2012, 1, 4, 23, 59, 59);
        
        System.out.println(">> " + beginCalendar.getTime().toString());
        
        Date beginDate = beginCalendar.getTime();
        Date endDate = endCalendar.getTime();
        List<WPPost> posts = getWPPostDAO().get(beginDate, endDate);
        
        for (WPPost wPPost : posts) {
            System.out.println(">> " + wPPost);
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        }
    }

    private static void testDateFormat() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        
        System.out.println(">> " + simpleDateFormat.format(GregorianCalendar.getInstance().getTime()));
    }

    private static void testAddPostByDAO() throws SQLException {
        List<String>  tags = new ArrayList<String>();
        List<String>  categories = new ArrayList<String>();

        categories.add("cinema");
        String title = "teste de elenilson 18";
        
        WPPostDAO dao = getWPPostDAO();
        Date date = GregorianCalendar.getInstance().getTime();
        
        WPPost post = new WPPost(title+ "çuúã", "conteudo éçpoeúi", title, 
                "http://www.lazerjp.com.br/wp-content/uploads/2011/04/cineespaco.jpg", 
                date, categories, tags);
        
        int result = dao.add(post);
        
        System.out.println(">> " + result);
    }
    
}
